<?php

/**
 * News Category Model
 * @author PhuND
 */
class Mnews_category extends CI_Model {

    private $tableName = 'news_category';

    public function __construct() {
        parent::__construct();
        $this->load->database();
    }

    /**
     * Get Category Row By Slug
     * @param string $slub
     * @return row
     */
    public function getBySlug($slug) {
        $this->db->cache_on();
        $this->db->select();
        $this->db->where("slug", "$slug");
        $this->db->order_by("order asc");
        $query = $this->db->get($this->tableName);
        return $query->row();
    }

    /**
     * List Category with ParentID
     * @return array
     */
    public function listParent() {
        $this->db->cache_on();
        $this->db->select("id, title, slug");
        $this->db->where("parentid", 0);
        $this->db->order_by("order asc");
        $query = $this->db->get($this->tableName);
        return $query->result_array();
    }

    /**
     * List News category with ParentID
     * @param int $parent_id
     * @return array
     */
    public function listChild($parent_id) {
        $this->db->select("id, title, slug");
        $this->db->where("parentid", $parent_id);
        $this->db->order_by("order desc");
        $query = $this->db->get($this->tableName);
        return $query->result_array();
    }

    /**
     * List All News category
     * @return array
     */
    public function listAll() {
        $this->db->cache_on();
        $query = $this->db->get($this->tableName);
        return $query->result_array();
    }

}